//
//  WmcCustomFilter.swift
//  YPWatermarkCamera
//
//  Created by Json on 2023/7/14.
//

import UIKit
import YPGraphicEngine

class WmcCustomFilter: YPGEBaseFilter {
    

    // 包含关系使用GPUImage的滤镜
    override open var gpuFilter: YPGPUImageFilter {
        return _gpuFilter
    }
    
    lazy var _gpuFilter: PRGPUImageSaturationFilter = {
        let filter = PRGPUImageSaturationFilter()
        filter.saturation = 1.5
        return filter
    }()
    
    
    class TestGPUFilter: PRGPUImageFilter {
//        let vertex =
//        """
//        attribute vec4 vPosition;
//
//        attribute vec2 vCoord;
//
//        varying vec2 textureCoordinate;
//
//        void main() {
//            gl_Position = vPosition;
//            textureCoordinate = vCoord;
//        }
//
//        """
        let shader =
        """
        precision mediump float;
        varying vec2 textureCoordinate;
        uniform sampler2D inputImageTexture;

        void main() {
            vec3 color = texture2D(inputImageTexture, textureCoordinate).rgb;
            color = mix(color, vec3(1.0), 0.15);
            color = pow(color, vec3(0.4545));
            gl_FragColor = vec4(color, 1.0);
        }
        """
        
        /** 灰色
         precision mediump float;
         varying vec2 textureCoordinate;
         //采样器
         uniform sampler2D inputImageTexture;

         void main(){
             vec4 color = texture2D(inputImageTexture, textureCoordinate);
             float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
             gl_FragColor = vec4(vec3(gray), color.a);
         }
         */
        
        /**
         
         varying highp vec2 textureCoordinate;
         uniform sampler2D inputImageTexture;
                  
         void main() {
            // 获取输入的颜色值
            lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
            
            // 对每一帧的每一颗像素进行处理
            lowp vec3 greyScaleColor = vec3(textureColor.r , textureColor.g * 1.5, textureColor.b * 1.5);
        
            // gl_FragColor两个参数，第1参为vec3颜色值，第2参为阿尔法通道，也就是透明度
            gl_FragColor = vec4(greyScaleColor, textureColor.a);
         }
         */
        
        
        override init() {
            super.init(fragmentShaderFrom: shader)
        }
        
        override init!(vertexShaderFrom vertexShaderString: String!, fragmentShaderFrom fragmentShaderString: String!) {
            super.init(vertexShaderFrom: vertexShaderString, fragmentShaderFrom: fragmentShaderString)
        }
    }
}
